﻿@page "/predefinedRanges"

<div class="d-md-flex flex-md-row-reverse align-items-center justify-content-between">
    <a class="btn btn-sm btn-bd-light my-2 my-md-0" href="https://github.com/jdtcn/BlazorDateRangePicker/blob/master/Demo.Shared/Pages/PredefinedRanges.razor"
       title="View this file on GitHub" target="_blank" rel="noopener">View on GitHub</a>
    <h3>Predefined Date Ranges</h3>
</div>

<Example Text="@ExampleText">
    <DateRangePicker Ranges="DateRanges" />
</Example>

@code{
    Dictionary<string, DateRange> DateRanges => new Dictionary<string, DateRange> {
            { "This month", new DateRange
                {
                    Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),
                    End = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddTicks(-1)
                }
            } ,
            { "Previous month" , new DateRange
                {
                    Start = new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1),
                    End = new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1).AddMonths(1).AddTicks(-1)
                }
            }
     };

    private string ExampleText = 
        "<DateRangePicker Ranges=\"DateRanges\" />\n\n" +
        "@code { \n    Dictionary<string, DateRange> DateRanges => new Dictionary<string, DateRange> {\n" +
        "        { \"This month\", new DateRange\n" +
        "                {\n" +
        "                    Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1),\n" +
        "                    End = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddTicks(-1)\n" +
        "                }\n" +
        "            }, ...\n" +
        "        };\n    }\n}";
}
